//获取应用实例
const device = wx.getSystemInfoSync();
const app = getApp();

Page({
  data: {
    canvasWi: '',
    canvasHe: '',
    phoboxW: '',
    phoboxH: '',
    imgbl: '',
    klboxt: '',
    klboxl: '',
    canvasw: 2000,
    imginterval: 10,
    widimg: '',
    heimg: '',
    widthimg: '',
    heightimg: '',
    toimg: 0,
    leimg: 0,
    toimgs: 0,
    leimgs: 0,
    starclick: '',
    pax: '',
    pay: '',
    whlin: '',
    kaungw: 350, //框宽
    kaungh: 350 * 7 / 5, //框高
    imgsf: '', //图片加载到屏幕缩放比例
    julione: 0, //两指头第一次放上去的距离
    julitow: '', //两指头第二次放上去的距离
    Scale: 1, //放大比例
    isColours: true,
    lvarr: [],
    livurl: '',
    pic: [],
    propic: '', //服务器下载下来到图片路径
    pics: '',
    r: 255,
    g: 255,
    b: 255,
    isShow: true,
    ispichw: 7 / 5,
    id: 2, //打印类型
    cicun: '', //打印尺寸id = 1 一寸，2 小二寸，3 二寸
    phoboxl: '',
    phoboxt: '',
    imgstopl: '',
    imgstopt: '',
    bgcolor: '', //背景填充色
    imagewidth: 0, // 缩放后的宽
    imageheight: 0, // 缩放后的高
    // 组件所需的参数
    nvabarData: {
      showCapsule: 1, //是否显示左上角图标   1表示显示    0表示不显示
      title: '证件照、签证', //导航栏 中间的标题
    },
    // 此页面 页面内容距最顶部的距离
    height: app.globalData.height * 2 + 20,
    pictrs: '' //canvas处理过后到图片路径
  },
  onLoad(options) {

    let that = this;

  },
  onShow(options) {
    let that = this;

    // 获取当前小程序的页面栈
    let pages = getCurrentPages();
    // 数组中索引最大的页面--当前页面
    let currentPage = pages[pages.length - 1];
    // 打印出当前页面中的 options
    console.log(currentPage.options)
    that.setData({
      cicun: currentPage.options.id
    })
    if (that.data.cicun == 1) {
      that.setData({
        kaungw: 350, //框宽
        kaungh: 490,
        ispichw: 49 / 35
      })
    } else if (that.data.cicun == 2) {
      that.setData({
        kaungw: 350,
        kaungh: 450,
        ispichw: 45 / 35
      })
    } else if (that.data.cicun == 3) {
      that.setData({
        kaungw: 350,
        kaungh: 530,
        ispichw: 53 / 35
      })
    } else if (that.data.cicun == 6) {
      that.setData({
        kaungw: 400,
        kaungh: 400,
        ispichw: 1
      })
    } else if (that.data.cicun == 7) {
      that.setData({
        kaungw: 400,
        kaungh: 400,
        ispichw: 1
      })
    } else if (that.data.cicun == 8) {
      that.setData({
        kaungw: 350,
        kaungh: 450,
        ispichw: 9 / 7
      })
    }
    let query = wx.createSelectorQuery()
    query.select('.phobox').boundingClientRect()
    query.selectViewport().scrollOffset()
    query.exec(function (res) {
      console.log(res)
      let phoboxW = res[0].width; // 要截取打印图片的宽度
      let phoboxH = res[0].height; // 要截取打印图片的高度
      that.setData({
        phoboxW: phoboxW,
        phoboxH: phoboxH
      })

    })

  },
  // 上传图片
  uploadImage: function () {
    let that = this;
    let pic = that.data.pic;
    wx.chooseImage({
      count: 1,
      sizeType: ['original', 'compressed'],
      sourceType: ['album', 'camera'],
      success(res) {
        wx.getImageInfo({
          src: res.tempFilePaths[0],
          success: function (res) {
            if (res.width > res.height) {
              that.setData({
                phoboxwill: res.width / res.height,
                widimg: that.data.kaungh * res.width / res.height,
                heimg: that.data.kaungh,
                widthimg: that.data.kaungh * res.width / res.height,
                heightimg: that.data.kaungh,
                originalScale: originalScale,
                whlin: res.width / res.height,
                imgww: res.width,
                imghh: res.height,
                pic: res.path
              })
            } else {
              that.setData({
                phoboxwill: res.width / res.height,
                widimg: that.data.kaungw,
                heimg: that.data.kaungw * res.height / res.width,
                widthimg: that.data.kaungw,
                heightimg: that.data.kaungw * res.height / res.width,
                originalScale: originalScale,
                whlin: res.width / res.height,
                imgww: res.width,
                imghh: res.height,
                pic: res.path
              })
            }
            console.log(res)

            wx.createSelectorQuery().select('.phoimgs').boundingClientRect(function (rect) {
              //图片放到屏幕缩放比例
              let rewid = rect.width;
              that.setData({
                imgsf: that.data.imgww / rewid
              })
            }).exec()
          }
        })
        // tempFilePath可以作为img标签的src属性显示图片
        let originalScale = res.height / res.width
        // console.log(tempFilePaths)
        that.setData({
          isShow: false,
          pic: res.tempFilePaths[0],
        })

      }, fail(res) {
        wx.showModal({
          title: '上传失败'
        })
      }
    })

  },
  // 触摸
  abtp(e) {
    if (e.touches.length == 1) {
      this.setData({
        pax: e.touches[0].pageX,
        pay: e.touches[0].pageY
      })

    } else if (e.touches.length == 2) {
      let julx = Math.abs(e.touches[0].pageX - e.touches[1].pageX)
      let july = Math.abs(e.touches[0].pageY - e.touches[1].pageY)
      let julione = Math.sqrt(julx * julx + july * july)
      this.setData({
        julione: julione
      })
    }
  },
  // 上传到服务器
  unloadfwq(src) {
    let that = this;
    // 上传到服务器
    var key = Math.random().toString(36).substr(2); //生成一个随机字符串的文件名
    let url = app.globalData.URL + 'common/upload'
    wx.uploadFile({
      url: url,
      filePath: src,
      header: {
        "Content-Type": "multipart/form-data",
        'accept': 'application/json',
        'Authorization': getApp().globalData.token //若有token，此处换上你的token，没有的话省略
      },
      name: 'file',
      formData: {
        'key': key //这里是为文件设置上传后的文件名
      },
      success: function (res) {
        console.log(res)
        let lvarr = JSON.parse(res.data)
        that.setData({
          lvarr: lvarr,
          livurl: lvarr.url,
          propic: lvarr.url,
        })

        console.log(lvarr, lvarr.url)
        let livurl = lvarr.url;
      },
      fail: function (res) {
        wx.showModal({
          title: '上传失败'
        })
      }
    })
  },

  // 监听手指移动时间
  seletime(e) {
    let that = this;
    // 图片移动
    if (e.touches.length == 1) {
      let liveX = that.data.pax - e.touches[0].pageX
      let liveY = that.data.pay - e.touches[0].pageY
      that.setData({
        toimg: that.data.toimgs - liveY,
        leimg: that.data.leimgs - liveX
      })

    } else if (e.touches.length == 2) {

      let liveX = Math.abs(e.touches[1].pageX - e.touches[0].pageX)
      let liveY = Math.abs(e.touches[1].pageY - e.touches[0].pageY)
      let julitow = Math.sqrt(liveX * liveX + liveY * liveY)
      let sjuli = julitow - that.data.julione
      //  图片放大
      let Scale = that.data.Scale;
      Scale = Scale + 0.001 * sjuli;
      if (Scale < 0.2 || Scale > 2.5) {
        return
      }
      that.setData({
        widimg: that.data.widthimg * Scale,
        heimg: that.data.heightimg * Scale,
        Scale: Scale
      })

      console.log(Scale)

    }
  },
  // 图片操作结束回调
  endimg(e) {
    let that = this;
    that.setData({
      toimgs: that.data.toimg,
      leimgs: that.data.leimg,

    })

  },


  // 换底色
  item_change: function (e) {
    let that = this;
    if (that.data.pic == '') {
      wx.showToast({
        title: '请先选择照片',
        icon: 'none',
        duration: 2000
      })
    } else {
      //将框里的图片截取出来
      wx.showLoading({
        title: '处理中。。',
      })
      // 上传到服务器
      var key = Math.random().toString(36).substr(2); //生成一个随机字符串的文件名
      let url = app.globalData.URL + 'common/upload'
      wx.uploadFile({
        url: url,
        filePath: that.data.pic,
        header: {
          "Content-Type": "multipart/form-data",
          'accept': 'application/json',
          'Authorization': getApp().globalData.token //若有token，此处换上你的token，没有的话省略
        },
        name: 'file',
        formData: {
          'key': key //这里是为文件设置上传后的文件名
        },
        success: function (res) {
          // 选择底色
          let type = e.currentTarget.id;
          that.setData({
            bgcolor: e.currentTarget.id
          })
          let r = that.data.r;
          let g = that.data.g;
          let b = that.data.b;
          console.log(res)
          let lvarr = JSON.parse(res.data)
          that.setData({
            lvarr: lvarr,
            livurl: lvarr.url,
            propic: lvarr.url,
          })
          if (type == 0) {
            that.setData({
              r: 255,
              g: 255,
              b: 255
            })
            that.gotophoto()
          } else if (type == 1) {
            that.setData({
              r: 0,
              g: 0,
              b: 0
            })
            that.gotophoto()
          } else if (type == 2) {
            that.setData({
              r: 0,
              g: 0,
              b: 255
            })
            that.gotophoto()
          } else if (type == 3) {
            that.setData({
              r: 255,
              g: 0,
              b: 0
            })
            that.gotophoto()
          }
        },
        fail: function (res) {
          console.log(res)
        }
      })
    }
  },
  // 处理图片背景改变
  gotophoto: function () {
    let that = this;
    let r = that.data.r;
    let g = that.data.g;
    let b = that.data.b;
    let url = app.globalData.URL + 'facility/printOrder/imgSet';
    let data = {
      path: that.data.propic,
      r: r,
      g: g,
      b: b
    };
    app.wxRequest('GET', url, data, (res) => {
      console.log(res);
      wx.hideLoading();
      if (res.code != 200) {
        wx.showToast({
          title: '图片格式错误',
          icon: 'none'
        })
        return
      }
      that.setData({
        propic: res.msg,
        pictrs: res.msg,
        pic: res.msg
      })
      wx.getImageInfo({
        src: that.data.propic,
        success: function (res) {
          console.log(res)
          that.setData({
            pic: res.path
          })
          console.log(that.data.pic)
        }
      })
    }, (err) => {
      console.log(err.errMsg)
      if (res.code != 200) {
        wx.showToast({
          title: '网络请求错误',
          icon: 'none'
        })
        return
      }
    })

  },
  // 去打印
  gopicplace_order: function () {
    let that = this;
    if (that.data.pic == '') {
      wx.showToast({
        title: '请先选择照片',
        icon: 'none',
        duration: 2000
      })
    } else {
      wx.showLoading({
        title: '正在生成订单。。。',
      })

      let rpx;
      // 获取不同手机屏幕自适应
      wx.getSystemInfo({
        complete: (res) => {
          rpx = res.windowWidth / 414;
        },
      })
      //将框里的图片截取出来
      let phoboxwill = that.data.imgsf * rpx; //图片缩放比例
      let canvswidth = that.data.imgww + that.data.leimg * phoboxwill; //画布宽度
      let canvsheight = that.data.imghh + that.data.toimg * phoboxwill; //画布高度
      let imgww = that.data.imgww * rpx;
      let imghh = that.data.imghh * rpx;
      let Scale = that.data.Scale;
      console.log(canvswidth, canvsheight)
      const ctx1 = wx.createCanvasContext('shareCanvas')
      that.setData({
        canvasHe: that.data.canvsheight,
        canvasWi: that.data.canvswidth
      })
      ctx1.fillRect(0, 0, canvswidth, canvsheight);
      ctx1.setFillStyle("#fff");
      let bgurl;
      if (that.data.bgcolor == 0) {
        bgurl = '../../../images/picture/bgA4.png'
      } else if (that.data.bgcolor == 1) {
        bgurl = '../../../images/picture/bgblack.png'
      } else if (that.data.bgcolor == 2) {
        bgurl = '../../../images/picture/bgblue.png'
      } else if (that.data.bgcolor == 3) {
        bgurl = '../../../images/picture/bgred.png'
      }
      ctx1.drawImage(bgurl, 0, 0, that.data.phoboxW * phoboxwill, that.data.phoboxW * phoboxwill * that.data.ispichw); //绘制图片
      ctx1.drawImage(that.data.pic, that.data.leimg * phoboxwill / 2 * 0.5, 0.5 * that.data.toimg * phoboxwill / 2 + (8 / 350 * that.data.phoboxW * phoboxwill * that.data.ispichw) * 0.5, imgww * Scale, imghh * Scale); //绘制图片

      //保存生成的单张图片
      ctx1.draw(false, function () {
        setTimeout(function () {
          wx.canvasToTempFilePath({ //把当前画布指定区域的内容导出生成指定大小的图片，并返回文件路径
            x: 0,
            y: 0,
            width: that.data.phoboxW * phoboxwill,
            height: that.data.phoboxW * phoboxwill * that.data.ispichw,
            canvasId: 'shareCanvas',
            fileType: 'jpg',
            success: function (res) {
              that.setData({
                pictrs: res.tempFilePath
              })
              let src = res.tempFilePath
              //  that.unloadfwq(src)
              console.log(src)
              if (that.data.cicun == 1) {
                // 一寸照片
                // 排版拼接
                const ctx = wx.createCanvasContext('shareCanvas1')
                let xw = that.data.phoboxW * phoboxwill / 3;
                let imginterval = xw * 1 / 12;
                let yw = that.data.phoboxW * phoboxwill * 7 / 5 / 3;

                ctx.fillRect(0, 0, ctx.width, ctx.height);
                ctx.setFillStyle("#fff");
                ctx.drawImage('../../../../images/picture/bgA4.png', 0, 0, 5.92 * xw, 3 * yw); //背景图

                // 第一行
                ctx.drawImage(src, imginterval, 3 * imginterval, xw, yw);
                ctx.drawImage(src, 2 * imginterval + xw, 3 * imginterval, xw, yw);
                ctx.drawImage(src, imginterval + 2 * (imginterval + xw), 3 * imginterval, xw, yw);
                ctx.drawImage(src, imginterval + 3 * (imginterval + xw), 3 * imginterval, xw, yw);
                ctx.drawImage(src, imginterval + 4 * (imginterval + xw), 3 * imginterval, xw, yw);
                // 第二行
                ctx.drawImage(src, imginterval, 6 * imginterval + yw, xw, yw);
                ctx.drawImage(src, 2 * imginterval + xw, 6 * imginterval + yw, xw, yw);
                ctx.drawImage(src, imginterval + 2 * (imginterval + xw), 6 * imginterval + yw, xw, yw);
                ctx.drawImage(src, imginterval + 3 * (imginterval + xw), 6 * imginterval + yw, xw, yw);
                ctx.drawImage(src, imginterval + 4 * (imginterval + xw), 6 * imginterval + yw, xw, yw);

                ctx.draw(false, function () {
                  setTimeout(function () {
                    wx.canvasToTempFilePath({ //把当前画布指定区域的内容导出生成指定大小的图片，并返回文件路径
                      x: 0,
                      y: 0,
                      width: 5.92 * xw,
                      height: 4.2 * xw,
                      fileType: 'jpg',
                      canvasId: 'shareCanvas1',
                      success: function (res) {
                        wx.hideLoading();
                        wx.navigateTo({
                          url: '/modelA/pages/drawings_printing/picplace_order/picplace_order?pics=' + res.tempFilePath + '&title=' + '一寸证件照' + '&ccinfo=' + '2.5*35cm' + '&type=' + that.data.type + '&isColours=' + that.data.isColours + '&id=' + that.data.id,
                        })
                      },
                    })
                  })
                })
              } else if (that.data.cicun == 2) {
                // 小二寸照片
                // 排版拼接
                const ctx = wx.createCanvasContext('shareCanvas1')
                let xw = that.data.phoboxW * phoboxwill / 2;
                let imginterval = xw * 0.8 / 5 / 3;
                let yw = that.data.phoboxW * phoboxwill * that.data.ispichw / 2;

                ctx.fillRect(0, 0, ctx.width, ctx.height);
                ctx.setFillStyle("#fff");
                ctx.drawImage('../../../../images/picture/bgA4.png', 0, 0, 5.92 * xw, 3 * yw); //背景图

                // 第一行
                ctx.drawImage(src, 3 * imginterval, 2 * imginterval, xw, yw);
                ctx.drawImage(src, 6 * imginterval + xw, 2 * imginterval, xw, yw);
                ctx.drawImage(src, 6 * imginterval + 2 * (imginterval + xw), 2 * imginterval, xw, yw);
                // ctx.drawImage(src, imginterval + 3 * (imginterval + xw), imginterval, xw, yw);

                // 第二行
                ctx.drawImage(src, 3 * imginterval, 4 * imginterval + yw, xw, yw);
                ctx.drawImage(src, 6 * imginterval + xw, 4 * imginterval + yw, xw, yw);
                ctx.drawImage(src, 6 * imginterval + 2 * (imginterval + xw), 4 * imginterval + yw, xw, yw);
                // ctx.drawImage(src, imginterval + 3 * (imginterval + xw), 2 * imginterval + yw, xw, yw);


                ctx.draw(false, function () {
                  setTimeout(function () {
                    wx.canvasToTempFilePath({ //把当前画布指定区域的内容导出生成指定大小的图片，并返回文件路径
                      x: -imginterval,
                      y: 0,
                      width: 14.8 / 3.5 * xw,
                      height: 10.5 / 3.5 * xw,
                      fileType: 'jpg',
                      canvasId: 'shareCanvas1',
                      success: function (res) {
                        wx.hideLoading();
                        wx.navigateTo({
                          url: '/modelA/pages/drawings_printing/picplace_order/picplace_order?pics=' + res.tempFilePath + '&title=' + '小二寸证件照' + '&ccinfo=' + '3.5*4.5cm' + '&type=' + that.data.type + '&isColours=' + that.data.isColours + '&id=' + that.data.id,
                        })
                      },
                    })
                  })
                })
              } else if (that.data.cicun == 3) {
                // 二寸照片
                // 排版拼接
                const ctx = wx.createCanvasContext('shareCanvas1')
                let xw = that.data.phoboxW * phoboxwill / 2;
                let imginterval = xw * (14.8 / 3.5 - 4) / 5;
                let yw = that.data.phoboxW * phoboxwill * that.data.ispichw / 2;

                ctx.fillRect(0, 0, ctx.width, ctx.height);
                ctx.setFillStyle("#fff");
                ctx.drawImage('../../../../images/picture/bgA4.png', 0, 0, 14.8 / 3.5 * xw, 3 * yw); //背景图

                // 第一行
                // ctx.drawImage(src, imginterval, imginterval, xw, yw);
                ctx.drawImage(src, 2 * imginterval, 2 * imginterval, xw, yw);
                ctx.drawImage(src, 4 * imginterval + xw, 2 * imginterval, xw, yw);
                // ctx.drawImage(src, imginterval + 3 * (imginterval + xw), imginterval, xw, yw);

                // // 第二行
                // ctx.drawImage(src, imginterval, 2 * imginterval + yw, xw, yw);
                ctx.drawImage(src, 2 * imginterval, 4 * imginterval + yw, xw, yw);
                ctx.drawImage(src, 4 * imginterval + xw, 4 * imginterval + yw, xw, yw);
                // ctx.drawImage(src, imginterval + 3 * (imginterval + xw), 2 * imginterval + yw, xw, yw);


                ctx.draw(false, function () {
                  setTimeout(function () {
                    wx.canvasToTempFilePath({ //把当前画布指定区域的内容导出生成指定大小的图片，并返回文件路径
                      x: -imginterval,
                      y: 0,
                      width: 10.5 / 3.5 * xw,
                      height: 14.8 / 3.5 * xw,
                      fileType: 'jpg',
                      canvasId: 'shareCanvas1',
                      success: function (res) {
                        wx.hideLoading();
                        wx.navigateTo({
                          url: '/modelA/pages/drawings_printing/picplace_order/picplace_order?pics=' + res.tempFilePath + '&title=' + '二寸证件照' + '&ccinfo=' + '3.5*5.3cm' + '&type=' + that.data.type + '&isColours=' + that.data.isColours + '&id=' + that.data.id,
                        })
                      },
                    })
                  })
                })
              } else if (that.data.cicun == 6) {
                // 美国签证
                // 排版拼接
                const ctx = wx.createCanvasContext('shareCanvas1')
                let xw = that.data.phoboxW * phoboxwill / 2;
                let imginterval = xw * (14.8 / 5 - 2) / 3;
                let yw = that.data.phoboxW * phoboxwill * that.data.ispichw / 2;

                ctx.fillRect(0, 0, ctx.width, ctx.height);
                ctx.setFillStyle("#fff");
                ctx.drawImage('../../../../images/picture/bgA4.png', 0, 0, 14.8 / 5 * xw, 3 * yw); //背景图

                // 第一行
                ctx.drawImage(src, imginterval, imginterval, xw, xw);
                ctx.drawImage(src, 2 * imginterval + xw, imginterval, xw, xw);
                // ctx.drawImage(src, imginterval + 2 * (imginterval + xw), imginterval, xw, yw);
                // ctx.drawImage(src, imginterval + 3 * (imginterval + xw), imginterval, xw, yw);

                // // 第二行
                // ctx.drawImage(src, imginterval, 2 * imginterval + yw, xw, yw);
                // ctx.drawImage(src, 2 * imginterval + xw, 2 * imginterval + yw, xw, yw);
                // ctx.drawImage(src, imginterval + 2 * (imginterval + xw), 2 * imginterval + yw, xw, yw);
                // ctx.drawImage(src, imginterval + 3 * (imginterval + xw), 2 * imginterval + yw, xw, yw);


                ctx.draw(false, function () {
                  setTimeout(function () {
                    wx.canvasToTempFilePath({ //把当前画布指定区域的内容导出生成指定大小的图片，并返回文件路径
                      x: 0,
                      y: 0,
                      width: 14.8 / 5 * xw,
                      height: 10.5 / 5 * xw,
                      fileType: 'jpg',
                      canvasId: 'shareCanvas1',
                      success: function (res) {
                        wx.hideLoading();
                        wx.navigateTo({
                          url: '/modelA/pages/drawings_printing/picplace_order/picplace_order?pics=' + res.tempFilePath + '&title=' + '美国签证' + '&ccinfo=' + '5.0*5.0cm' + '&type=' + that.data.type + '&isColours=' + that.data.isColours + '&id=' + that.data.id,
                        })
                      },
                    })
                  })
                })
              } else if (that.data.cicun == 7) {
                // 日本签证
                // 排版拼接
                const ctx = wx.createCanvasContext('shareCanvas1')
                let xw = that.data.phoboxW * phoboxwill / 2;
                let imginterval = xw * (14.8 / 4.5 - 2) / 3;
                let yw = that.data.phoboxW * phoboxwill * that.data.ispichw / 2;

                ctx.fillRect(0, 0, ctx.width, ctx.height);
                ctx.setFillStyle("#fff");
                ctx.drawImage('../../../../images/picture/bgA4.png', 0, 0, 14.8 / 4.5 * xw, 3 * yw); //背景图

                // 第一行
                ctx.drawImage(src, imginterval, imginterval, xw, xw);
                ctx.drawImage(src, 2 * imginterval + xw, imginterval, xw, xw);
                // ctx.drawImage(src, imginterval + 2 * (imginterval + xw), imginterval, xw, yw);
                // ctx.drawImage(src, imginterval + 3 * (imginterval + xw), imginterval, xw, yw);

                // // 第二行
                // ctx.drawImage(src, imginterval, 2 * imginterval + yw, xw, yw);
                // ctx.drawImage(src, 2 * imginterval + xw, 2 * imginterval + yw, xw, yw);
                // ctx.drawImage(src, imginterval + 2 * (imginterval + xw), 2 * imginterval + yw, xw, yw);
                // ctx.drawImage(src, imginterval + 3 * (imginterval + xw), 2 * imginterval + yw, xw, yw);


                ctx.draw(false, function () {
                  setTimeout(function () {
                    wx.canvasToTempFilePath({ //把当前画布指定区域的内容导出生成指定大小的图片，并返回文件路径
                      x: 0,
                      y: 0,
                      width: 14.8 / 4.5 * xw,
                      height: 10.5 / 4.5 * xw,
                      fileType: 'jpg',
                      canvasId: 'shareCanvas1',
                      success: function (res) {
                        wx.hideLoading();
                        wx.navigateTo({
                          url: '/modelA/pages/drawings_printing/picplace_order/picplace_order?pics=' + res.tempFilePath + '&title=' + '日本签证' + '&ccinfo=' + '4.5*4.5cm' + '&type=' + that.data.type + '&isColours=' + that.data.isColours + '&id=' + that.data.id,
                        })
                      },
                    })
                  })
                })
              } else if (that.data.cicun == 8) {
                // 瑞士欧洲签证
                // 排版拼接
                const ctx = wx.createCanvasContext('shareCanvas1')
                let xw = that.data.phoboxW * phoboxwill / 2;
                let imginterval = xw * (14.8 / 3.5 - 2) / 4;
                let yw = that.data.phoboxW * phoboxwill * 9 / 7 / 2;

                ctx.fillRect(0, 0, ctx.width, ctx.height);
                ctx.setFillStyle("#fff");
                ctx.drawImage('../../../../images/picture/bgA4.png', 0, 0, 14.8 / 3.5 * xw, 3 * yw); //背景图

                // 第一行
                ctx.drawImage(src, imginterval, imginterval, xw, yw);
                ctx.drawImage(src, 2 * imginterval + xw, imginterval, xw, yw);
                // ctx.drawImage(src, imginterval + 2 * (imginterval + xw), imginterval, xw, yw);
                // ctx.drawImage(src, imginterval + 3 * (imginterval + xw), imginterval, xw, yw);

                // // 第二行
                // ctx.drawImage(src, imginterval, 2 * imginterval + yw, xw, yw);
                // ctx.drawImage(src, 2 * imginterval + xw, 2 * imginterval + yw, xw, yw);
                // ctx.drawImage(src, imginterval + 2 * (imginterval + xw), 2 * imginterval + yw, xw, yw);
                // ctx.drawImage(src, imginterval + 3 * (imginterval + xw), 2 * imginterval + yw, xw, yw);


                ctx.draw(false, function () {
                  setTimeout(function () {
                    wx.canvasToTempFilePath({ //把当前画布指定区域的内容导出生成指定大小的图片，并返回文件路径
                      x: 0,
                      y: 0,
                      width: 14.8 / 3.5 * xw,
                      height: 10.5 / 3.5 * xw,
                      fileType: 'jpg',
                      canvasId: 'shareCanvas1',
                      success: function (res) {
                        wx.hideLoading();
                        wx.navigateTo({
                          url: '/modelA/pages/drawings_printing/picplace_order/picplace_order?pics=' + res.tempFilePath + '&title=' + '瑞士欧洲签证' + '&ccinfo=' + '3.5*4.5cm' + '&type=' + that.data.type + '&isColours=' + that.data.isColours + '&id=' + that.data.id,
                        })
                      },
                    })
                  })
                })
              }
            },
          })
        }, 300)
      });
    }
  }
})